$(function(){
    var obj = {
        cityName: '',
        searchKey: '',
        searchId: $.getQueryString('id'),
        telNum: '',
        submitFlag: false,
        swiper1:null,
        swiper2:null,
        init: function () {
            var that = this;
            that.telNum = that.userTel = localStorage.getItem('myTel') || '';
            var data = [ {
                "id" : "2",
                "phone" : "15857502013",
                "lxr" : "冯翔",
                "fl" : "带薪年假、生日补贴、免费体检",
                "address" : "华宇路108号",
                "gw" : "保安",
                "zprs" : "10",
                "xc" : "4000",
                "xs" : "绍兴县",
                "xzjd" : "柯桥街道",
                "zpyq" : "数据库里面记录是高薪诚聘才艺女主播！\n没有经验？没有人脉？没有渠道？\n这一切都不是问题！只要你有兴趣就来吧！\n新加入的你将获得公司大力扶持与栽培！\n公司将集合所有资源，以培养更多的百万级网红为己任！\n机不可失，失不再来！我们热烈期待您的加入！\n任职要求：\n1.形象气质佳，性格外向，善于交流\n2.有个人魅力和特点，才艺或有直播经验优先考虑\n3.无经验者公司提供免费专业培训，运营一对一指导，带薪上岗\n4.公司提供住宿，直播间专业设备，服装，化妆等\n5.公司不收取任何费用以及押金",
                "zpdw" : "绿城物业",
                "xl": '高中'
            }];
            that.fillDetail(data[0]);
            that.ajaxGetJobDetail();
            that.addEvent();
            var history = localStorage.getItem('submitHistory') || '{}';
            history = JSON.parse(history)
            if(history[that.telNum]&&history[that.telNum][that.searchId])
                that.submitFlag = true;
        },
        addEvent: function () {
            var that = this;
            //返回
            $('.historyBack').click(function () {
                history.go(-1);
            });
            $('#applyJob').click(function () {
                if(!that.telNum) alert('您还未登录！');
                if(!that.submitFlag) that.ajaxApply();
            })
        },
        ajaxGetJobDetail: function() {
            var that = this;
            $.getData({
                url: $.getAjaxHost('def') + 'zpinfo/list',
                //url: $.getAjaxHost('def') + 'cxjy/zpinfo/getListById',
                type: 'get',
                contentType: 'application/json',
                data: {id: that.searchId},
                success: function (res) {
                    that.fillJobsList(res.data[0]);
                },
                error: function (res) {
                }
            })
        },
        ajaxApply:function () {
            var that = this;
            $.getData({
                url: $.getAjaxHost('def') + 'zpinfo/submit',
                //url: $.getAjaxHost('def') + 'cxjy/zpinfo/getListById',
                type: 'get',
                contentType: 'application/json',
                data: {id: that.searchId,telNum: that.telNum},
                success: function (res) {
                    that.submitFlag = true;
                    $('#applyJob').addClass('disable');
                    $('#applyJob').html('已提交申请');
                    $.alert('申请成功，请耐心等待');
                    var history = localStorage.getItem('submitHistory') || {};
                    history[that.telNum] = {}
                    history[that.telNum][that.searchId] = new Date();
                    localStorage.setItem('submitHistory',JSON.stringify(history));
                },
                error: function (res) {
                }
            })
        },
        fillDetail: function (data) {
            var that = this;
            data.flTags =  data.fl?data.fl.split('、'):[];
            data.tel = data.phone.slice(0,3)+'****'+data.phone.slice(-4);
            var zpyq = data.zpyq.replace(/\n/g,"<br>");
            var html = template('jobIntro', data);
            $('#detail').html(html);
            $('#yq').html(zpyq);
            that.initAdsSwiper();
        },
        initAdsSwiper: function () {
            var that = this;
            that.swiper2 = new Swiper('#adsBox', {
                //direction: 'vertical',
                autoplay: 5000,
                speed: 350,
                noSwiping:true,
                noSwipingClass:'swiper-slide',
                loop:true,
                autoplayDisableOnInteraction: false,
                pagination: '.swiper-pagination1',

            });
            that.swiper2 = new Swiper('#adsBoxBottom', {
                //direction: 'vertical',
                autoplay: 5000,
                speed: 350,
                noSwiping:true,
                noSwipingClass:'swiper-slide',
                loop:true,
                autoplayDisableOnInteraction: false,
                pagination: '.swiper-pagination2',

            });
        }
    };
    obj.init();
});